const vm = require('vm')
const path = require('path')
const fs = require('fs')


function r(filename) {
    const pathName = path.resolve(__dirname, filename)
    const textContent = fs.readFileSync(pathName, 'utf-8')

    const wapper = [
        '(function (require, module, exports) {',
        '\n})'
    ]
    const wapperContent = wapper[0] + textContent + wapper[1]
    const script = new vm.Script(wapperContent, {
        filename: 'index.js'
    })

    const result = script.runInThisContext()
        // console.log('result-----', result)

    let module = {
        exports: {

        }
    }
    result(r, module, module.exports)
    return module.exports
}
module.exports = r